//==========Ajax请求=============
function doPost(url, data, callback, isAsync){
    api.ajax({
        url:url,
        data:data,
        method:"post",
        dataType:'json',
        async:isAsync,
        headers:{token:$api.getStorage("token")}
    },function(ret, err){
      if (ret) {
            callback(ret);
      }else {
        api.toast({
             msg: err.msg,
             duration: 2000,
             location:"middle"
        });
      }
    });
}

function doGet(url, data, callback, isAsync){
    api.ajax({
        url:url,
        data:data,
        method:"get",
        dataType:'json',
        async:isAsync,
        headers:{token:$api.getStorage("token")}
    },function(ret, err){
      if (ret) {
           callback();
      }else {
        toast.fail({
            title: '网络错误',
            duration: 2000
        });
      }
    });
}

//异步
function AsyncPost(url, data, callback){
    doPost(url, data, callback, true);
}
function AsyncGet(url, data, callback){
    doGet(url, data, callback, true);
}

function SyncPost(url, data, callback){
    doPost(url, data, callback, false);
}

function SyncGet(url, data, callback){
    doGet(url, data, callback, false);
}
